package cn.wanda.bi.sunshine.platform.server.service;

import cn.wanda.bi.sunshine.platform.server.bean.mapper.CityMapper;
import cn.wanda.bi.sunshine.platform.server.bean.model.City;
import cn.wanda.bi.sunshine.platform.server.bean.model.CityExample;
import cn.wanda.bi.sunshine.platform.server.client.response.elasticsearch.UserLabelBean;
import cn.wanda.bi.sunshine.platform.server.client.response.elasticsearch.UserLabelBucket;
import cn.wanda.bi.sunshine.platform.server.controller.request.LabelQueryRequest;
import cn.wanda.bi.sunshine.platform.server.controller.response.CityResponse;
import cn.wanda.bi.sunshine.platform.server.controller.response.common.SimpleResponse;
import cn.wanda.bi.sunshine.platform.server.utils.PasswordUtil;

import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by James on 17/7/26.
 */
@Service
public class CityService {

    public static final Logger logger = LoggerFactory.getLogger(CityService.class);

    @Autowired
    private CityMapper cityMapper;

    @Cacheable(value = "cache:city", key = "'cache:city:cityname:'+#cityName")
	public City querySingle(String cityName) {
        CityExample cityExample = new CityExample();
        CityExample.Criteria criteria = cityExample.createCriteria();
        if (StringUtils.isNotEmpty(cityName))
            criteria.andAreanameEqualTo(cityName);
        List<City> cities = cityMapper.selectByExample(cityExample);
        if (cities != null && cities.size() > 0)
            return cities.get(0);
        return null;
    }

}
